package com.webside.points.wechat;

import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;



public class BeanFactory {
	
	private static AbstractApplicationContext context = null;
	
	static{
		try {
			context = new ClassPathXmlApplicationContext(
					new String[]{"classpath:spring-mvc.xml"}
					);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public static Object getBean(String name){
		return context.getBean(name);
	}
	
	public static Object getBean(final String beanId, final Class<?> requiredType){
		return context.getBean(beanId, requiredType);
	}
	
	public static synchronized void autowireComponent(final Object bean){
		try {
			((AbstractApplicationContext)context).getBeanFactory().autowireBeanProperties(bean, 
					AutowireCapableBeanFactory.AUTOWIRE_BY_NAME,false);
		} catch (final Exception e) {
			e.printStackTrace();
		}
	}
	

	
	
}
